import com.alibaba.fastjson.JSON
import org.apache.spark.sql.{DataFrame, SparkSession}

object CheckDataDetail2 {

  val year = 2021
  val month = 6
  val day = 5

  def main(args: Array[String]): Unit = {

    val spark = SparkSession.builder()
      .appName("CheckDataDetail")
      .config("spark.debug.maxToStringFields", "500")
      .config("spark.serializer", "org.apache.spark.serializer.KryoSerializer")
      .config("spark.sql.caseSensitive", "true")
      .config("es.nodes", "192.168.1.29")
      .config("es.index.read.missing.as.empty", "true")
      .config("es.net.http.auth.user", "elastic")
      .config("es.net.http.auth.pass", "changeme")
      .config("es.port", "9200")
      .config("cluster.name", "O2OElastic")
      .config("spark.sql.crossJoin.enabled", "true")
      .master("local[*]")
      .getOrCreate()

    val sc = spark.sparkContext
    sc.hadoopConfiguration.set("fs.s3a.access.key", "GAO7EO9FWKPJ8WFCQDME")
    sc.hadoopConfiguration.set("fs.s3a.secret.key", "LZ0xaHBSYKHaJ9ECDbX9f7zin79UZkXfGoNapRPL")
    sc.hadoopConfiguration.set("fs.s3a.endpoint", "https://obs.cn-north-1.myhuaweicloud.com")
    sc.setLogLevel("WARN")


        val resaultPath = spark.read.orc(s"s3a://dws-data/g_data/2021/7/aomygad/").registerTempTable("tab")
//        val resaultPath = spark.read.orc(s"s3a://o2o-dataproces-group/zyf/2021/620/miya/good/").registerTempTable("tab")
//    val resaultPath = spark.read.orc(s"s3a://o2o-dataproces-group/zyf/2021/620/wangyiyanxuan/").registerTempTable("tab")

//        resaultPath.repartition(1).write.json("D://test")

//          resaultPath.where("sellcount > 0").selectExpr("count(1)","sum(sellcount)","sum(salesamount)").show()
    spark.sql(
      """
        |select
        |count(1),
        |sum(sellCount),
        |sum(salesAmount)
        |from
        |tab
      """.stripMargin).show(false)

    // 统计 is_oversea = true 的
//    spark.sql(
//      """
//        |select
//        |count(1),
//        |sum(sellCount),
//        |sum(salesAmount)
//        |from
//        |tab
//        |where
//        |is_oversea = true
//      """.stripMargin).show(false)
  }
}
